package com.mdd.admin.service.setting.impl;

import com.mdd.admin.service.setting.IRechargeConfigService;
import com.mdd.admin.validate.setting.RechargeConfigValidate;
import com.mdd.common.utils.ConfigUtil;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.LinkedHashMap;
import java.util.Map;

@Service
public class RechargeConfigServiceImpl implements IRechargeConfigService {

    @Override
    public Map<String, Object> getConfig() {
        Map<String, String> config = ConfigUtil.get("recharge");
        String rechargeOpen = config.getOrDefault("rechargeOpen", "0");
        String minRechargeAmount = config.getOrDefault("minRechargeAmount", "0");
        Map<String, Object> map = new LinkedHashMap<>();
        map.put("rechargeOpen", Integer.valueOf(rechargeOpen));
        map.put("minRechargeAmount", new BigDecimal(minRechargeAmount));
        return map;
    }

    @Override
    public void setConfig(RechargeConfigValidate rechargeConfigValidate) {
        ConfigUtil.set("recharge","rechargeOpen", rechargeConfigValidate.getRechargeOpen().toString());
        ConfigUtil.set("recharge", "minRechargeAmount", rechargeConfigValidate.getMinRechargeAmount().toString());
    }
}
